// 关注动态页
//  MZY_AttentionViewController.m
//  FullHouse
//
//  Created by dllo on 16/2/29.
//  Copyright © 2016年 yy. All rights reserved.
//

#import "MZY_AttentionViewController.h"
#import "DataBaseHandle.h"
#import "MZY_PictureModel.h"
#import "UIImageView+WebCache.h"
#import "MZY_collectTableViewCell.h"
#import "MZY_LikeDetailViewController.h"

@interface MZY_AttentionViewController ()<UITableViewDataSource,UITableViewDelegate>

@property(nonatomic, retain)UITableView *tableView;
@property(nonatomic, retain)NSMutableArray *arr;

@end

@implementation MZY_AttentionViewController

- (void)dealloc
{
    [self.tableView release];
    [self.arr release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self createView];
}

#pragma mark 创建界面
- (void)createView{
    self.navigationController.navigationBar.hidden = NO;
    self.view.backgroundColor = [UIColor orangeColor];
    self.title = @"关注动态";
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(0, 0, 20, 20);
    [button setImage:[UIImage imageNamed:@"iconfont-arrowleft.png"] forState:UIControlStateNormal];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
    [button addTarget:self action:@selector(backAction:) forControlEvents:UIControlEventTouchUpInside];
    
    // 创建"tableView"
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 64) style:UITableViewStylePlain];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.rowHeight = 100;
    [self.view addSubview:self.tableView];
    [self.tableView registerClass:[MZY_collectTableViewCell class] forCellReuseIdentifier:@"reuse"];
    [self.tableView release];
    
    self.arr = [[DataBaseHandle shareDB] selectAllPic];
    NSLog(@"%@",NSHomeDirectory());
}

#pragma mark "tableView"的第一个必须执行的方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.arr.count;
}

#pragma mark "tableView"的第二个必须执行的方法
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    MZY_collectTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reuse" forIndexPath:indexPath];
    MZY_PictureModel *pic = self.arr[indexPath.row];
    cell.wordLabel.text = pic.col_name;
    [cell.picImageView sd_setImageWithURL:[NSURL URLWithString:pic.pic]];
    return cell;
}

#pragma mark "tableView"的点击方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    self.hidesBottomBarWhenPushed = YES;
    MZY_LikeDetailViewController *likeVC  = [[MZY_LikeDetailViewController alloc]init];
    [self.navigationController pushViewController:likeVC animated:YES];
    MZY_PictureModel *pic = self.arr[indexPath.row];
    likeVC.idStr = pic.photo_id;
    likeVC.picStr = pic.pic_detail;
    likeVC.addCount = pic.col_count;
    likeVC.commentCount = pic.comment_count;
    likeVC.face = pic.author_face;
    likeVC.nick = pic.author_nick;
    likeVC.name = pic.col_name;
    likeVC.firstphoto = pic.col_photos[0][@"pic"];
    likeVC.secondphoto= pic.col_photos[1][@"pic"];
    likeVC.thirdphoto = pic.col_photos[2][@"pic"];
    self.hidesBottomBarWhenPushed = NO;
}

#pragma mark 返回按钮
- (void)backAction:(UIButton *)button{
    [self.navigationController popToRootViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
